<cfmodule template="../../tag/layout.cfm">
<cfinclude template="../../inc/lib.cfm">

<!--- 表格显示 --->
<table id="grid"></table>
<div id="toolbar" style="display: none;">
	<table>
		<tr>
			<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".save"))>
			<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
			</cfif>
			<td><a onclick="redoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_next'">展开</a><a onclick="undoFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-resultset_previous'">折叠</a></td>
			<td><a onclick="grid.treegrid('reload');" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'ext-icon-arrow_refresh'">刷新</a></td>
		</tr>
	</table>
</div>
</cfmodule>
<cfscript>
	if( structKeyExists(rc, "categorytypeid")  && rc.categorytypeid > 0 ){
		categorytypeid = rc.categorytypeid;
	}else{
		categorytypeid = 0;
	}
</cfscript>
<script type="application/javascript">
//删除操作
var removeFun = function(id) {
    parent.$.messager.confirm('询问', '您确定要删除此记录？',
    function(r) {
        if (r) {
            $.post('?action=category.delete', {
                id: id
            },
            function() {
                grid.treegrid('reload');
            },
            'json');
        }
    });
};
//查看操作
var showFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '查看信息',
        url: '?action=category.form&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>&id=' + id,
        buttons: [{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};
//新增操作
var addFun = function() {
    var dialog = parent.fw.modalDialog({
        title: '新增信息',
        url: '?action=category.form&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>',
        buttons: [
        {
            text: '新增记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$, parent.mainMenu);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}
//修改操作
var editFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '修改信息',
        url: '?action=category.form&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>&id=' + id,
        buttons: [
        {
            text: '修改记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$, parent.mainMenu);
            }
        },{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};

//表单定义操作
var formDesign = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '表单定义',
        url: '?action=category.formdesign&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>&id=' + id,
        buttons: [
        {
            text: '修改记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};

var redoFun = function() {
	var node = grid.treegrid('getSelected');
	if (node) {
		grid.treegrid('expandAll', node.id);
	} else {
		grid.treegrid('expandAll');
	}
};
var undoFun = function() {
	var node = grid.treegrid('getSelected');
	if (node) {
		grid.treegrid('collapseAll', node.id);
	} else {
		grid.treegrid('collapseAll');
	}
};

$(function(){
	//列表操作
	var gird;
	grid = $('#grid').treegrid({
		fit:true,
	    border:false,
        rownumbers: true,
        animate:true,
        collapsible:false,
        fitColumns:true,
        pagination: false,
        url:'?action=category.list&categorytypeid=<cfoutput>#categorytypeid#</cfoutput>',
        idField:'id',
        treeField:'text',
        columns:[[
            {title:'id',field:'id',width:'50',hidden: false},
            {field:'text',title:'类别名称',width:'200'},
            {field:'url',title:'链接地址',width:'200',
	        formatter: function(value, row) {
	            if (value) {
	                return fw.formatString('<span title="{0}">{1}</span>', value, value);
	            }
	        }},
	         {field:'description',title:'类别描述',width:'180'},
	         {field:'created',title:'创建时间',width:'80',hidden:true},
	         {field:'edited',title:'修改时间',width:'80',hidden:true},
	         {field:'seq',title:'排序值',width:'50',align:'center'},
	         {
				title : '操作',
				field : 'action',
				width : '60',
				formatter : function(value, row) {
					var str = '';
					
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".form"))>
						str += fw.formatString('<img class="iconImg ext-icon-note" title="查看" onclick="showFun(\'{0}\');"/>', row.id);
						</cfif>
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".update"))>
						str += fw.formatString('<img class="iconImg ext-icon-note_edit" title="编辑" onclick="editFun(\'{0}\');"/>', row.id);
						</cfif>
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".delete"))>
						str += fw.formatString('<img class="iconImg ext-icon-note_delete" title="删除" onclick="removeFun(\'{0}\');"/>', row.id);
						</cfif>
						
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".formdesign"))>
						str += fw.formatString('<img class="iconImg ext-icon-building_edit" title="表单定义" onclick="formDesign(\'{0}\');"/>', row.id);
						</cfif>
					return str;
				}
			}
        ]],
        toolbar: '#toolbar',
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
		}
    });
	
	
});
</script>